<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


    require'db_con.php';
    $page=isset($_GET['page'])?$_GET['page']:1;//当前第几页
    $pagesize=3;//每页显示三条
    $first=($page-1)*$pagesize;//起始位置
    if (isset($_GET['search']))
    {
        $search=$_GET['search'];
        $sql="select * from t_message where (message like '%{$search}%') or (username like '%{$search}%') order by id desc";

    }
 else 
 {
     $search="";
     $sql="select * from t_message order by id desc";      
}

    $result=$db->query($sql);
    $num=$result->num_rows;
    
    $maxpage=ceil($num/$pagesize);//最大页码
        if (isset($_GET['search']))
    {
        $search=$_GET['search'];
        $sql="select * from t_message where (message like '%{$search}%') or (username like '%{$search}%') order by id desc limit {$first},{$pagesize}";

    }
 else 
 {
     $search="";
     $sql="select * from t_message order by id desc limit {$first},{$pagesize}";      
}
    //$sql="select * from t_message order by id desc limit {$first},{$spgesize}";
    $result=$db->query($sql);
    $bbsdata=$result->fetch_all(MYSQLI_BOTH);
    $result->free_result();
    $db->close();
    //var_dump($bbsdata);
    require 'list_html.php';